package com.fuyu.system.models.form;

import com.fuyu.system.entity.SysMenu;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

@Data
public class SysMenuForm {
    @Schema(description = "菜单id")
    private Long menuId;

    @Schema(description = "父菜单id")
    @NotNull(message = "父菜单id不能为空")
    private Long parentId;

    @Schema(description = "请求地址")
    @NotBlank(message = "菜单类型不能为空")
    private String path;

    @Schema(description = "组件地址")
    private String component;

    @Schema(description = "重定向")
    private String redirect;

    @Schema(description = "菜单名称")
    @NotBlank(message = "菜单类型不能为空")
    private String title;

    @Schema(description = "菜单图标")
    private String icon;

    @Schema(description = "显示顺序")
    private Integer sort;

    @Schema(description = "打开方式（menuItem页签 menuBlank新窗口）")
    private String target;

    @Schema(description = "菜单类型（M目录 C菜单 F按钮）")
    @NotBlank(message = "菜单类型不能为空")
    private String menuType;

    @Schema(description = "菜单状态（0显示 1隐藏）")
    private String visible;

    @Schema(description = "是否刷新（0刷新 1不刷新）")
    private String isRefresh;

    @Schema(description = "权限标识")
    private String mark;

    @Schema(description = "备注")
    private String remark;


    public static SysMenu toEntity(SysMenuForm form) {

        SysMenu sysMenu = new SysMenu();
        sysMenu.setMenuId(form.getMenuId());
        sysMenu.setParentId(form.getParentId());
        sysMenu.setPath(form.getPath());
        sysMenu.setComponent(form.getComponent());
        sysMenu.setRedirect(form.getRedirect());
        sysMenu.setTitle(form.getTitle());
        sysMenu.setIcon(form.getIcon());
        sysMenu.setSort(form.getSort());
        sysMenu.setTarget(form.getTarget());
        sysMenu.setMenuType(form.getMenuType());
        sysMenu.setVisible(form.getVisible());
        sysMenu.setIsRefresh(form.getIsRefresh());
        sysMenu.setMark(form.getMark());
        sysMenu.setRemark(form.getRemark());

        return sysMenu;
    }
}
